package com.zyf.concurrency.chapter14;

import com.zyf.concurrency.annotations.GuardedBy;
import com.zyf.concurrency.annotations.ThreadSafe;

/**
 * 使用wait和notifyAll来实现可重新关闭的阀门
 * create by yifeng
 */
@ThreadSafe
public class ThreadGate {
    @GuardedBy("this")
    private boolean isOpen;
    @GuardedBy
    private int generation;

    public synchronized void close() {
        isOpen = false;
    }

    public synchronized void open() {
        ++generation;
        isOpen = true;
        notifyAll();
    }

    public synchronized void await() {
        int arrivalGeneration = generation;
    }
}
